<?php

namespace app\common\model;
use think\Model;

class Usergroup extends Model {

	protected $table = 'ns_user_group';

	/**
	 * 获取会员等级列表
	 *
	 * @return array()
	 */
	public function getList() {
		$list = $this->paginate();
		return $list;
	}

	public function rmusergroup($id) {
		$rst = $this->where('id', $id)->delete();
		if ($rst) {
			return ['code' => 1, 'msg' => '已经移除！'];
		}
		return ['code' => 0, 'msg' => '稍后重试'];
	}

	public function getInfo($id) {
		$info = $this->where('id', $id)->find();
		return $info;
	}

	public function editInfo($data) {
		$info = $this->where('id', $data['id'])->find();
		if (($data['group_name'] != $info['group_name']) || ($data['quota'] != $info['quota']) || ($data['spread'] != $info['spread']) || ($data['take_per'] != $info['take_per']) || ($data['sign_reward'] != $info['sign_reward']) || ($data['sign_condition'] != $info['sign_condition'])) {
			$id = array('id' => $data['id']);
			unset($data['id']);
			$where = $data;
			$where['updata_time'] = date('Y-m-d H:i:s', time());
			if ($this->save($where, $id)) {
				return ['code' => 1, 'msg' => '已修改'];
			} else {
				return ['code' => 0, 'msg' => '稍后重试'];
			}
		}
		return ['code' => 0, 'msg' => '您未做修改'];

	}

	public function addInfo($data) {
		if ($this->save($data)) {
			return ['code' => 1, 'msg' => '添加成功'];
		} else {
			['code' => 0, 'msg' => '稍后重试'];
		}
	}
}